%{
#include <iostream>
#include <string>
using namespace std;
void yyerror (const char *error);
extern "C"
{
        int yyparse(void);
        int yylex(void);
        int yywrap()
        {
                return 1;
        }

}
%}
%union {
  int       value;  /* For the lexical analyser. NUMBER tokens */
  char      *ident;  /* For the lexical analyser. IDENT tokens */
}



%token <ident> IDENT
%token <value> NUMBER
%token ASSIGNOP

%%


program: stmt_list 
       ;

stmt_list:  stmt ';' stmt_list 
        |   stmt  
        ;

stmt:  assign_stmt 
       | expr  
    ;

assign_stmt: IDENT ASSIGNOP expr 
           ;


expr: expr '+' term   
    | expr '-' term   
    | term            
    ;

term: term '*' factor   
    | factor            
    ;

factor:     '(' expr ')'  
    |       NUMBER 
    |       IDENT 
    ;
%%

int main()
{
return yyparse();
}

void yyerror (const char *error)
{
  cout << error << endl;
}
